getApp();

var dataApi = require("../../provider/dataApi.js");

require("../../provider/pipe.js");

Page({
    data: {
        type: 2,
        scrollHeight: "",
        statusBarHeight: "",
        titleBarHeight: "",
        rankingArray: [ "全国排行" ],
        rankingArrayIndex: 0,
        statisticsChart: [],
        myExamInfo: {},
        info: {},
        list: [],
        userInfo: ""
    },
    goSwitch: function(event) {
        this.setData({
            type: event.currentTarget.dataset.type
        });
    },
    chakan: function() {
        wx.showModal({
            title: "提示",
            content: "每天做题达到" + this.data.info.dabiao_num + "道视为达标",
            showCancel: !1,
            success: function(response) {}
        });
    },
    onLoad: function(options) {
        this.setData({
            statusBarHeight: getApp().globalData.statusBarHeight,
            titleBarHeight: getApp().globalData.titleBarHeight
        }), options = wx.getSystemInfoSync().windowHeight;
        var windowHeight = wx.getSystemInfoSync().windowWidth;
        this.setData({
            scrollHeight: 750 * options / windowHeight - 144
        });
    },
    bindPickerChange: function(event) {
        var selectedIndex = parseInt(event.detail.value) + 1;
        console.log(selectedIndex), this.setData({
            rankingArrayIndex: event.detail.value
        }), this.ranking(selectedIndex);
    },
    onShow: function() {
        this.getAchievement(), this.getUserInfo(), this.ranking(this.data.rankingArrayIndex + 1);
    },
    getUserInfo: function() {
        var self = this;
        dataApi.userinfo({
            uid: wx.getStorageSync("uid"),
            op: "getinfo"
        }).then(function(response) {
            response = response.data.info, wx.setStorageSync("userinfo", response), self.setData({
                userInfo: response,
                rankingArray: 1 == response.stu_have ? [ "全国排行", "校内排行", "班内排行" ] : [ "全国排行" ]
            });
        }).catch(function(error) {
            console.log(error);
        });
    },
    getAchievement: function() {
        var self = this;
        dataApi.getAchievement({
            uid: wx.getStorageSync("uid"),
            op: "myexam_info"
        }).then(function(response) {
            console.log(response);
            var achievementData = {};
            achievementData.calculate = response.data.calculate;
            achievementData.doexamNum = response.data.doexam_num;
            achievementData.dotestNum = response.data.dotest_num;
            achievementData.myScore = response.data.myscore;
            achievementData.notDoNum = response.data.not_donum;
            achievementData.passNum = response.data.pass_num;
            achievementData.rightLv = response.data.right_lv;
            self.setData({
                statisticsChart: response.data.tongji_chart,
                myExamInfo: achievementData,
                info: response.data.info
            });
        }).catch(function(error) {
            console.log(error);
        });
    },
    ranking: function(rankType) {
        var self = this, userInfo = this.data.userInfo;
        dataApi.getAchievement({
            uid: wx.getStorageSync("uid"),
            school_id: userInfo.school_id,
            banji_id: userInfo.banji_id,
            op: "ranking",
            rankType: rankType
        }).then(function(response) {
            console.log(response), self.setData({
                list: response.data.list
            });
        }).catch(function(error) {
            console.log(error);
        });
    },
    onShareAppMessage: function() {}
});